package com.hmall.common.config;
/*
  Date: 2023/12/02
  Author: Luochao
  Description:
*/

import com.hmall.common.interceptor.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * common被不同包依赖，包扫描不会扫描到com/hmall/common，所以需要到src/main/resources/META-INF/spring.factories记录！！！
 */
@Configuration
@ConditionalOnClass(DispatcherServlet.class)        //只有满足包含 DispatcherServlet.class 条件时候才会装配，ps：只有网关没有该class
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());
//        registry.addInterceptor(new UserInfoInterceptor()).addPathPatterns("*");      //默认拦截所有路径
    }
}
